﻿/*
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
* published by the Free Software Foundation.
*
* Alternatively, this software may be distributed under the terms of BSD
* license.
*
*
*
* Authors:					zhoujian
* Email:			343600434@qq.com
* Date:			Aug-28-2025 13:20:16
*
*/


#ifndef __shuffle_H__
#define __shuffle_H__

#include <stdint.h>



#ifdef __cplusplus
extern "C" {
#endif






typedef enum{
	SHUFFLE_State_0x00 = 0x00,
	SHUFFLE_State_0x01 = 0x01,
	SHUFFLE_State_0x02 = 0x02,
	SHUFFLE_State_0x03 = 0x03,
}SHUFFLE_zTypeDef;

enum{
	POKER_IDLE,
	POKER_OUT,//300
	POKER_NO_IN,//300->50
	POKER_FALLING,//25->150
	POKER_FALLINTO,
};


///////////////AI GEN///////////////


#define SHUFFLE_STATE_MACHINE


#ifdef SHUFFLE_STATE_MACHINE

// 状态定义
typedef enum {
    STATE_IDLE,
	STATE_START,
    STATE_CHECK_FORCE,
    STATE_FORCE_SHUFFLE_REV,
    STATE_FORCE_SHUFFLE_LOOP,
    STATE_CHECK_POKER_ENTERING,
    STATE_CONTINUOUS_SHUFFLE,
    STATE_STOP_SHUFFLE,
    STATE_ERROR
} ShuffleState;

// 单次洗牌状态定义
typedef enum {
    SHUFFLE_ONCE_IDLE,
    SHUFFLE_ONCE_FIRST_DIRECTION,
    SHUFFLE_ONCE_FIRST_DELAY,
    SHUFFLE_ONCE_FIRST_ADC,
    SHUFFLE_ONCE_SECOND_DIRECTION,
    SHUFFLE_ONCE_SECOND_DELAY,
    SHUFFLE_ONCE_SECOND_ADC,
    SHUFFLE_ONCE_COMPLETE
} ShuffleOnceState;

// 反向洗牌状态定义
typedef enum {
    SHUFFLE_REV_IDLE,
    SHUFFLE_REV_START,
    SHUFFLE_REV_DELAY1,
    SHUFFLE_REV_ADC1,
    SHUFFLE_REV_STOP,
    SHUFFLE_REV_DELAY2,
    SHUFFLE_REV_ADC2,
    SHUFFLE_REV_CHECK_ENTERING,
    SHUFFLE_REV_COMPLETE
} ShuffleRevState;


// 状态机上下文结构
typedef struct {
    ShuffleState current_state;
    ShuffleOnceState shuffle_once_state;
    ShuffleRevState shuffle_rev_state;
    uint8_t force;
    uint8_t start_time;
    uint8_t i;
    uint8_t poker_entering;
    uint32_t adc;
    uint32_t pre_adc;
    uint8_t continue_send_;
    uint8_t retry_count;
    uint32_t delay_start_time;
	uint8_t adj_delay;
    uint8_t sel; // For shuffle_once direction selection
    uint8_t rev_i; // For shuffle_once_rev loop counter
} ShuffleStateMachine;

extern ShuffleStateMachine sm;
void shuffle_state_machine_step(ShuffleStateMachine* sm);
void shuffle_init();

#endif


//////////////////////////////////





void shuffle_card_1(uint8_t force);
void shuffle_card_2(uint8_t force);

extern uint8_t no_poker_need_shuffle;



#define shuffle_card shuffle_card_1




#ifdef __cplusplus
}
#endif

#ifdef __cplusplus
class shuffle
{

public:
    shuffle();
    ~shuffle();

};
#endif



#endif
